package cn.com.cifi.mars.web.action.sys;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import cn.com.cifi.mars.bean.bo.SysLogBO;
import cn.com.cifi.mars.bean.vo.sys.req.UpdateSysProjectFetchNumberParam;
import cn.com.cifi.mars.bean.vo.sys.rsp.ProjectVo;
import cn.com.cifi.mars.bean.vo.sys.rsp.RegionVo;
import cn.com.cifi.mars.bean.vo.sys.rsp.SysProjectFetchNumberVo;
import cn.com.cifi.mars.common.base.BaseAction;
import cn.com.cifi.mars.common.bean.R;
import cn.com.cifi.mars.constant.LogEventEnum;
import cn.com.cifi.mars.constant.LogSrcEnum;
import cn.com.cifi.mars.entity.common.IdmUser;
import cn.com.cifi.mars.service.SysLogService;
import cn.com.cifi.mars.service.SysProjectFetchNumberService;
import cn.com.cifi.mars.util.WebUtils;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyd
 * @since 2019-09-21
 */
@RestController
public class SysProjectFetchNumberController extends BaseAction implements ISysProjectFetchNumberController{

	@Autowired
	private SysProjectFetchNumberService sysProjectFetchNumberService;
	
	@Autowired
	private SysLogService sysLogService;
	
	
	/**
	 * 分页项目取数
	 */
	@Override
	public R<SysProjectFetchNumberVo> getSysProjectFetchNumber(String apiVersion,String current,String pageSize, String regionId, String projectId,
			String countingSystemId,String beginTime,String endTime,String cityId,String stagesId) {
		return ok(sysProjectFetchNumberService.querySysProjectFetchNumber(current,pageSize,regionId,projectId,countingSystemId,beginTime,endTime,cityId,stagesId));
	}

	/**
	 * 更改取数系统
	 */
	@Override
	public R<String> updateSysProjectFetchNumber(String apiVersion, UpdateSysProjectFetchNumberParam param) {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		IdmUser user = getOperator();
		// 新增日志
		SysLogBO bo = new SysLogBO();
		bo.setEvent(LogEventEnum.EDIT);
		bo.setSource(LogSrcEnum.PC);
		bo.setIp(WebUtils.getIpAddr(request));
		bo.setUrl(WebUtils.getUrl(request));
		bo.setModule("系统配置");
		bo.setTitle("更改取数系统");
		bo.setContent("更改取数系统");
		boolean msg = sysLogService.add(bo, user.getAlias());
		return ok(sysProjectFetchNumberService.update(param));
	}

	/**
	 * 增量拉取主数据到项目取数表(前端勿动)
	 */
	@Override
	public R<String> createSysProjectFetchNumberV2(String apiVersion, String projectId) {
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		IdmUser user = getOperator();
		// 新增日志
		SysLogBO bo = new SysLogBO();
		bo.setEvent(LogEventEnum.ADD);
		bo.setSource(LogSrcEnum.PC);
		bo.setIp(WebUtils.getIpAddr(request));
		bo.setUrl(WebUtils.getUrl(request));
		bo.setModule("系统配置");
		bo.setTitle("增量拉取主数据到项目取数表");
		bo.setContent("增量拉取主数据到项目取数表");
		boolean msg = sysLogService.add(bo, user.getAlias());
		return ok(sysProjectFetchNumberService.syncProjectFetchNumber(projectId,null));
	}

	/**
	 * 删除项目取数
	 */
	@Override
	public R<String> deleteSysProjectFetchNumber(String apiVersion, String id) {
		return ok(sysProjectFetchNumberService.delete(id));
	}

}
